<?php
error_reporting(E_ALL);
ini_set('display_errors','On');

require_once("../config.inc.php");

//path to directory to scan
$sDir = PATCHES_DIR;
$sTmpDir = DAEMON_DIR;

$aPatches = glob($sDir."*.{patch-id-,diff-id-}*", GLOB_BRACE);
$aRunningPatch = glob($sTmpDir."*.{patch-id-,diff-id-}*", GLOB_BRACE);

$aFiltered = array();

foreach ($aPatches as &$p) {
	$sName = basename($p);
	if (substr($sName,-5) == "-done") continue;
	
	$aFiltered[] = $sName;
}

if (!empty($aRunningPatch)) $aFiltered["running"] = basename($aRunningPatch[0]);

//print each file name
echo json_encode($aFiltered);
?>